import os
from volcenginesdkarkruntime import Ark
from app import settings


client = Ark(
    api_key=settings.HuoShan_API_KEY,
    timeout=120,
    max_retries=2)
def get_response(prompt,chat_history):
    """
    Get response from HuoShan model
    prompt: str # 提示词+用户数据+用户提问
    chat_history: list # 对话历史
    return: str
    """
    system_prompt = prompt.split("用户提问：")[0]
    question = prompt.split("用户提问：")[1]
    system_dict = {"role": "system", "content": system_prompt}
    user_dict = {"role": "user", "content": question},
    chat_history.insert(0,system_dict)
    chat_history.append(user_dict)
    completion = client.chat.completions.create(
                model="ep-20250206165256-8fqqx",
                messages = chat_history,
            )
    return completion.choices[0].message.content
